<template>
  <div
    class="main-page"
    style="min-width:1366px;"
  >
    <el-form ref="form">
      <!-- 搜索栏 -->
      <BaseSearchBar v-on:ChildSearchEvent="getSearchAntimicorList"></BaseSearchBar>
    </el-form>
    <!-- 表单 -->
    <el-card
      :body-style="{ padding: '0px' }"
      class="box-card"
    >
      <!-- <div class="SearchT">
        <div class="tableLable">数据管理列表</div>
        <el-button type="danger" class="BatchDeleBtn" style="width:80px" size="small">批量删除</el-button>

        <el-button type="primary" class="exportBtn" style="width:80px" size="small">导出</el-button>
      </div> -->
      <div class="tableStyle">
        <el-table
          ref="multipleTable"
          class="card-table"
          :data="AntimicrobialList"
          tooltip-effect="dark"
          style="font-size:12px"
          :header-cell-style="{ background: '#3F9DFD', color: '#FFF' }"
          size="medium"
          stripe
          border
          height="634px"
        >
          <el-table-column
            label="序号"
            type="index"
            width="50"
          ></el-table-column>

          <el-table-column
            prop="drugCode"
            label="医院药品编码"
            show-overflow-tooltip
            width="150"
          />
          <el-table-column
            prop="drugName"
            label="医院药品名称"
            show-overflow-tooltip
            width="400"
          />
          <el-table-column
            label="抗菌药"
            show-overflow-tooltip
            width="160"
          >
            <template slot-scope="scope">{{(scope.row.is_anti==1)?'是':'否'}}</template>
          </el-table-column>
          <el-table-column
            label="抗菌药物级别(可编辑)"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.antilevel"
                @change="changeantilevel(scope.row.drugUniqueCode, $event)"
                size="small"
              >
                <el-option
                  v-for="item in AntibacGrade"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-sizes="[20, 50, 100]"
            :page-size="queryInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
          ></el-pagination>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import BaseSearchBar from "./BaseSearchBar";
import BaseSearchBarItem from "../../../components/BaseSearchBarItem";
import { getAntimicrobialList, changeantilevel } from "@/api/rad";
export default {
  name: "MainPage",
  components: {
    BaseSearchBar
  },
  created: function() {
    this.getAntimicrobialList();
  },
  methods: {
    // 监听pagesize改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getAntimicrobialList();
      // console.log(newSize)
    },
    // 当前展示的页面
    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      this.getAntimicrobialList();
      // console.log(newPage)
    },
    async getAntimicrobialList() {
      let _this = this;
      let res = await this.$rad.getAntimicrobialList({
        srm: _this.queryInfo.srm,
        is_anti: _this.queryInfo.is_anti,
        antilevel: _this.queryInfo.antilevel,
        page: _this.queryInfo.page,
        pageSize: _this.queryInfo.pageSize
      });
      this.AntimicrobialList = res.rows;
      this.total = res.total;
      console.log(res);
    },
    getSearchAntimicorList(data) {
      this.queryInfo.srm = data.srm;
      this.queryInfo.is_anti = data.is_anti;
      this.queryInfo.antilevel = data.antilevel;
      this.getAntimicrobialList();
    },
    async changeantilevel(drugUniqueCode, e) {
      console.log(drugUniqueCode);
      console.log(e);
      var res = await this.$rad.changeantilevel({
        drugUniqueCode: drugUniqueCode,
        antilevel: e
      });
      console.log(res.code);
      if (res.code == 1) {
        this.$message.success(res.msg);
      } else {
        this.$message.error(res.msg);
        this.getAntimicrobialList();
      }
    }
  },
  data() {
    return {
      // 列表的参数对象
      queryInfo: {
        srm: "",
        // 当前的页数
        is_anti: "",
        antilevel: "",
        page: 1,
        // 当前页显示多少数据
        pageSize: 20
      },
      total: 0,
      AntimicrobialList: [],
      AntibacGrade: [
        {
          value: -1,
          label: "非抗菌药物"
        },
        {
          value: 1,
          label: "非限制使用"
        },
        {
          value: 2,
          label: "限制使用"
        },
        {
          value: 3,
          label: "特殊使用"
        }
      ]
    };
  }
};
</script>
<style scoped>
.el-card {
  margin-left: 3px;
}
.SearchT {
  display: flex;
  justify-content: flex-end;
  height: 50px;
  align-items: center;
  background-color: #e6edf3;
  font-size: 14px;
}
.tableLable {
  flex: 1;
  text-align: left;
  margin-left: 15px;
  letter-spacing: 2px;
  font-size: 14px;
  color: #32a6f3;
  font-weight: bold;
}
.exportBtn {
  margin-right: 23px;
}
.BatchDeleBtn {
  margin-right: 15px;
}
.tableStyle {
  width: 100%;
  height: 100%;
}
.card-table {
  width: 100%;
  height: 75%;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
</style>
